import { baseURL } from '../axios.config';
import { get, post, Response } from '/@/api/http'
const serverContextPath = '/example-server'
export interface SysFile{
	id: string;
	fileName: string;
	fileType: string;
	fileSize: string;
	filePath: string;
	fileState: string;
	businessId: string
	belongModule: string;
	memo: string;
	storeType: string;
}
export const fileApi = {
	/**
	 * 根据业务ID查询附件信息
	 * @param businessId 业务ID
	 * @returns 
	 */
	getFileListByBusinessId: (businessId: string) => {
		return get<SysFile[]>({
			url: serverContextPath + '/sysFile/getFileListByBusinessId/' + businessId
		})
	},
	/**
	 * 下载附件
	 * @param id 
	 */
	downloadFile: (id: string) => {
		var a = document.createElement("a");
		a.href = baseURL + serverContextPath + "/sysFile/downloadFile/" + id
		a.click();
	},
	/**
	 * 删除附件
	 * @param id 
	 * @returns 
	 */
	deleteFileById: (id: string) => {
		return post({
			url: serverContextPath + '/sysFile/remove/' + id
		})
	},
	/**
	 * 上传文件
	 * @param formData 
	 * @returns 
	 */
	importCommon: (formData: any) => {
		return post({
			url: serverContextPath + '/sysFile/importCommon',
			data: formData,
			headers: { 'Content-Type': 'multipart/form-data; charset=utf-8' },
		}
		)
	},
	getFileUploadUrl: () => {
		return `${import.meta.env.VITE_API_URL}/${serverContextPath}/sysFile/importCommon`
	}

}